<%@ page import="com.jy.dao.UserDao" %>
<%@ page import="com.jy.entity.Student" %>
<%@ page import="com.jy.entity.Teacher" %>
<%@ page import="com.jy.dao.impl.UserDaoImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <%
        Object act=request.getSession().getAttribute("act");
        Object sf=request.getSession().getAttribute("sf");
        UserDao user=new UserDaoImpl();
        Student s = null;
        Teacher t=null;
        if(sf=="student") {
            s = user.getstuid((String) act);
        }else{
            t=user.getteacher("select *from teacher where tname=?",act);
        }
        System.out.println("用户名:"+act);
        System.out.println("身份:"+sf);
    %>
    <title>试卷中心</title>
    <link rel="icon" href="../images/logo.png" type="image/x-icon">
    <link rel="stylesheet" href="../css/bootstrap.css">
    <link rel="stylesheet" href="../css/fonts.css">
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/core.min.js"></script>
    <script src="../js/script.js"></script>

    <style>
        body{
            height: 100%;
        }
        .nav1 {
            position: relative; /* 设置相对定位 */
            padding-left: 30px;
            display: inline-block; /* 让元素具有块级元素和行内元素的特性,即将块级元素转化为内联元素 */
        }

        .nav2 {
            display: none; /* 将某元素隐藏起来 */
            position: absolute; /* 绝对定位 */
            background-color: #f9f9f9;
            min-width: 81px; /* 最小宽度 */
        }

        #d1{
            width:100%;
            position: relative;
        }

        .index-title-h3 {
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
            -webkit-box-direction: normal;
            box-sizing: inherit;
            font-size: 22px;
            font-weight: 400;
            color: #1f2f3d;
            border-left: 10px solid #2ce8b4;
            padding-left: 10px;
            margin-left: 252px;
        }
        #sj{
            margin-left: 245px;
        }

        .bottom clearfix {
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
            -webkit-box-direction: normal;
            color: #303133;
            box-sizing: inherit;
            margin-top: 13px;
            line-height: 12px;
        }

       .el-card__body{
           line-height: 1.15;
           -webkit-text-size-adjust: 100%;
           -webkit-font-smoothing: antialiased;
           text-rendering: optimizeLegibility;
           font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
           -webkit-box-direction: normal;
           color: #303133;
           box-sizing: inherit;
           width:217px;
           height:216px;
           float: left;
           margin-right:50px;
           box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
           margin-bottom: 20px;
       }
        .image{
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
            -webkit-box-direction: normal;
            color: #303133;
            box-sizing: inherit;
            border-style: none;
            width: 107px;
            height: 107px;
            display: block;
            margin: 20px auto 10px auto;
        }
        .el-col el-col-4 el-col-offset-0{
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
            -webkit-box-direction: normal;
            float: left;
            box-sizing: border-box;
            margin-left: 0;
            width: 16.66667%;
        }
        .el-card is-always-shadow{
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
            -webkit-box-direction: normal;
            box-sizing: inherit;
            border-radius: 4px;
            overflow: hidden;
            border: 1px solid #ebeef5;
            background-color: #fff;
            color: #303133;
            transition: .3s;
            box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
        }
        #gd1{
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
            font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
            -webkit-box-direction: normal;
            color: #303133;
            box-sizing: inherit;
            font-size: 16px;
        }

        .el-button button el-button--text el-button--medium{
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            -webkit-box-direction: normal;
            font-family: inherit;
            overflow: visible;
            text-transform: none;
            -webkit-user-select: none;
            display: inline-block;
            line-height: 1;
            white-space: nowrap;
            cursor: pointer;
            -webkit-appearance: none;
            text-align: center;
            box-sizing: border-box;
            outline: 0;
            margin: 0;
            transition: .1s;
            font-weight: 500;
            border-color: transparent;
            font-size: 14px;
            border-radius: 4px;
            color: #409eff;
            background: 0 0;
            padding: 0;
            float: right;
        }
        #ks{
            -webkit-text-size-adjust: 100%;
            -webkit-font-smoothing: antialiased;
            -webkit-box-direction: normal;
            font-family: inherit;
            text-transform: none;
            -webkit-user-select: none;
            line-height: 1;
            white-space: nowrap;
            cursor: pointer;
            text-align: center;
            font-weight: 500;
            font-size: 14px;
            color: #66b1ff;
            box-sizing: inherit;
        }
        #cf{
            height:450px;
        }
    </style>
</head>
<div>
    <header class="page-header">

        <div class="rd-navbar-wrap">
            <nav class="rd-navbar rd-navbar-classic" data-layout="rd-navbar-fixed" data-sm-layout="rd-navbar-fixed" data-md-layout="rd-navbar-fixed" data-md-device-layout="rd-navbar-fixed" data-lg-layout="rd-navbar-static" data-lg-device-layout="rd-navbar-fixed" data-xl-layout="rd-navbar-static" data-xl-device-layout="rd-navbar-static" data-lg-stick-up-offset="46px" data-xl-stick-up-offset="46px" data-xxl-stick-up-offset="46px" data-lg-stick-up="true" data-xl-stick-up="true" data-xxl-stick-up="true">
                <na class="rd-navbar-main-outer">
                    <div class="rd-navbar-main">

                        <div class="rd-navbar-panel">

                            <button class="rd-navbar-toggle" data-rd-navbar-toggle=".rd-navbar-nav-wrap"><span></span></button>

                            <div class="rd-navbar-brand"><a class="brand" href="/examproject/nologin/index.jsp"><img class="brand-logo-dark" src="/examproject/images/logo.png" alt="" width="245" height="50"/><img class="brand-logo-light" src="../images/logo.png" alt="" width="245" height="50"/></a>
                            </div>
                        </div>
                        <div class="rd-navbar-nav-wrap">

                            <div class="rd-navbar-nav">
                                <li class="rd-nav-item active"><a class="rd-nav-link" href="/examproject/nologin/index.jsp">首页</a>
                                </li>
                                <li class="rd-nav-item"><a class="rd-nav-link" href="/examproject/html/mncs.jsp">模拟测试</a>
                                </li>
                                <div class="nav1">
                                    <li class="rd-nav-item"><a class="rd-nav-link" href="/examproject/stu/gettimetest" onmouseover="showmore('showdiv2')" onmouseout="nonemore('showdiv2')">试卷中心</a>
                                    </li>
                                    <div class="nav2" id="showdiv2" onmouseover="showmore(this.id)" onmouseout="nonemore(this.id)">
                                        <a class="rd-nav-link" href="/examproject/stu/gettimetest" >班级试卷</a>
                                        <br/>
                                        <a class="rd-nav-link" href="/examproject/stu/gettimetest">时段试卷</a>
                                        <br/>
                                        <a class="rd-nav-link" href="/examproject/stu/gettimetest">固定试卷</a>
                                    </div>
                                </div>
                                <div class="nav1">
                                    <li class="rd-nav-item"><a class="rd-nav-link" href="/examproject/stu/getvideo" onmouseover="showmore('showdiv1')" onmouseout="nonemore('showdiv1')">课堂视频</a>
                                    </li>
                                    <div class="nav2" id="showdiv1" onmouseover="showmore(this.id)" onmouseout="nonemore(this.id)">
                                        <a class="rd-nav-link" href="/examproject/stu/getvideo" >教学视频</a>
                                        <br/>
                                        <a class="rd-nav-link" href="/examproject/stu/getvideo">课堂回放</a>

                                    </div>
                                </div>
                                <%if(sf=="student"||sf==null){%>
                                <li class="rd-nav-item" style="padding-left: 45px;"><a class="rd-nav-link" href="/examproject/stu/getexamrecord">考试记录</a>
                                </li>
                                <%}%>
                                <div class="nav1">
                                    <li class="rd-nav-item"><a class="rd-nav-link" href="#" onmouseover="showmore('showdiv')" onmouseout="nonemore('showdiv')">更多</a>
                                    </li>
                                    <div id="showdiv" class="nav2" onmouseover="showmore(this.id)" onmouseout="nonemore(this.id)">
                                        <%if(sf=="student"||sf==null){%>
                                        <a class="rd-nav-link" href="/examproject/stu/falsebook" >错题本</a>
                                        <br/>
                                        <a class="rd-nav-link" href="/examproject/stu/findclass">我的班级</a>
                                        <br/>
                                        <a class="rd-nav-link" href="/examproject/stu/queryJ">留言板</a>
                                        <%}else{%>
                                        <a class="rd-nav-link" href="/examproject/html/zyqk.jsp">作业情况</a>
                                        <%}%>
                                    </div>
                                </div>
                                <div style="padding-left: 100px;">
                                    <li class="rd-nav-item">
                                        <%if(act==null){%>
                                        <a class="rd-nav-link" href="/examproject/nologin/LogInTo.jsp">登陆</a>||
                                        <a class="rd-nav-link" href="/examproject/nologin/Register.jsp">注册</a>
                                        <%}else{%>
                                        <div class="nav1">
                                            <%if(sf=="student"&&s.getStavatar()!=null){%>
                                            <img src="<%=s.getStavatar()%>" style="border-radius: 24px;width:48px;height:48px;">
                                            <%}else if(sf=="teacher"&&t.getThavatar()!=null){%>
                                            <img src="<%=t.getThavatar()%>" style="border-radius: 24px;width:48px;height:48px;">
                                            <%}else{%>
                                            <img src= "/examproject/images/mrtx.png" style="border-radius: 24px;width:48px;height:48px;">
                                            <%}%>
                                            <a class="rd-nav-link" onclick="yh('showdiv3')" href="#"><%=act%></a>
                                            <div class="nav2" id="showdiv3" onmouseover="showmore(this.id)" onmouseout="nonemore(this.id)">
                                                <a class="rd-nav-link" href="/examproject/stu/myinfo" >个人信息</a>
                                                <br/>
                                                <a class="rd-nav-link" href="/examproject/no/remove">退出</a>
                                            </div>
                                        </div>
                                        <%}%>
                                    </li>
                                </div>
                                </ul>
                            </div>
                        </div>
                    </div>
                </na>
            </nav>
        </div>
    </header>
    <div id="d1">
        <h3 data-v-30b99046="" class="index-title-h3"
            style="border-left: 10px solid rgb(54, 81, 212);margin-top: 22px;margin-bottom:22px">班级考试</h3>
        <div style="padding-left: 15px;" id="sj">
            <c:forEach items="${list1}" var='b'>
                <div class="el-card__body" style="padding: 0px;" id="body">
                    <c:choose>
                        <c:when test="${b.exam_avatar==null}">
                            <img data-v-30b99046="" src="/examproject/images/logo.png" class="image">
                        </c:when>
                        <c:otherwise>
                            <img data-v-30b99046="" src="${b.exam_avatar}" class="image">
                        </c:otherwise>
                    </c:choose>
                    <div data-v-30b99046="" style="padding: 1px;margin-left:1px "><span data-v-30b99046="" id="gd1" style="margin-left: 45px">${b.exam_name}</span>
                        <div data-v-30b99046="" class="bottom clearfix">
                            <a data-v-30b99046="" href="#" onclick="pd(this.id,'${b.exam_time_limit}')" class="a" id="${b.exam_id}">
                                <button data-v-30b99046="" type="button" class="el-button button el-button--text el-button--medium">
                                    <span id="ks" style="margin-left: 35px">开始做题</span>
                                </button>
                            </a>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
<div id="cf"></div>
<div id="d1">
    <h3 data-v-30b99046="" class="index-title-h3" style="margin-top: 22px;margin-bottom:22px">时段试卷</h3>
    <div style="padding-left: 15px;" id="sj">
        <c:forEach items="${list}" var='b'>
        <div class="el-card__body" style="padding: 0px;" id="body">
            <c:choose>
                <c:when test="${b.exam_avatar==null}">
                    <img data-v-30b99046="" src="/examproject/images/logo.png" class="image">
                </c:when>
                <c:otherwise>
                    <img data-v-30b99046="" src="${b.exam_avatar}" class="image">
                </c:otherwise>
            </c:choose>
        <div data-v-30b99046="" style="padding: 1px;margin-left:1px "><span data-v-30b99046="" id="gd1" style="margin-left: 45px">${b.exam_name}</span>
            <div style="margin-left: 10px">${b.exam_start_date}<div style="margin-left: 95px">||</div>${b.exam_end_date}</div>
                <div data-v-30b99046="" class="bottom clearfix">
                    <a data-v-30b99046="" href="#" onclick="time(this.id,'${b.exam_time_limit}')" class="a" id="${b.exam_id}">
                        <button data-v-30b99046="" type="button" class="el-button button el-button--text el-button--medium">
                            <span id="ks" style="margin-left: 35px">开始做题</span>
                            <input type="hidden" id="start${b.exam_id}" value="${b.exam_start_date}">
                            <input type="hidden" id="end${b.exam_id}" value="${b.exam_end_date}">
                        </button>
                    </a>
                </div>
            </div>
        </div>
            </c:forEach>
        </div>
</div>
<div id="cf"></div>
<div id="d1">
    <h3 data-v-30b99046="" class="index-title-h3" style="border-left: 10px solid rgb(220, 208, 65); margin-top: 22px;margin-bottom:22px">固定试卷</h3>
    <div style="padding-left: 15px;" id="sj">
        <c:forEach items="${list2}" var='b'>
            <div class="el-card__body" style="padding: 0px;" id="body">
                <c:choose>
                    <c:when test="${b.exam_avatar==null}">
                        <img data-v-30b99046="" src="/examproject/images/logo.png" class="image">
                    </c:when>
                    <c:otherwise>
                        <img data-v-30b99046="" src="${b.exam_avatar}" class="image">
                    </c:otherwise>
                </c:choose>
                <div data-v-30b99046="" style="padding: 1px;margin-left:1px "><span data-v-30b99046="" id="gd1" style="margin-left: 45px">${b.exam_name}</span>
                    <div data-v-30b99046="" class="bottom clearfix">
                        <a data-v-30b99046="" href="#" onclick="pd(this.id,'${b.exam_time_limit}')" class="a" id="${b.exam_id}">
                            <button data-v-30b99046="" type="button" class="el-button button el-button--text el-button--medium">
                                <span id="ks" style="margin-left: 35px">开始做题</span>
                            </button>
                        </a>
                    </div>
                </div>
            </div>
        </c:forEach>
    </div>

    </div>
</div>

</body>
<script src="../js/core.min.js"></script>
<script src="../js/script.js"></script>
<script>
    var xmlhttp=new XMLHttpRequest();
    function pd(id,time){

        xmlhttp.open("GET","/examproject/stu/pdexam?exam_id="+id,true);
        xmlhttp.send();
        xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState==4 && xmlhttp.status==200){
                    if(xmlhttp.responseText!="[]"){
                        alert("你已参加该考试,请前往考试记录查看")
                    }else{
                        var tftm=localStorage.getItem("begin");
                        if(tftm!=1){
                            var nowtime=new Date().getTime();
                            var tm=time*60*1000;
                            var tme=nowtime+tm;
                            localStorage.setItem("kdate"+id,tme);
                            let date = new Date()
                            //时间格式化
                            var kssj= dateFormat("YYYY-mm-dd HH:MM:SS", date);
                            //设置开始时间
                            localStorage.setItem("startime"+id,kssj);
                        }
                        localStorage.setItem("begin"+id,1);
                        location.href="/examproject/stu/gettestcontent?exid="+id;
                    }

            }
        }
    }
    function time(id,shu) {
        xmlhttp.open("GET","/examproject/stu/getnowtime",true);
        xmlhttp.send();
        xmlhttp.onreadystatechange=function(){
            var start=document.getElementById("start"+id);
            var end=document.getElementById("end"+id);
            if(xmlhttp.readyState==4 && xmlhttp.status==200){
                var begin=new Date(start.value);
                var js=new Date(end.value);
                var now=new Date(xmlhttp.responseText);
                console.log("开始毫秒数:"+begin.getTime())
                console.log("结束毫秒数:"+js.getTime())
                console.log("现在的毫秒数:"+now.getTime())
                if(now.getTime()<begin.getTime()||now.getTime()>js.getTime()){
                    alert("不在考试时间范围内!!!")
                    return;
                }else {
                    pd(id,shu)
                }
            }
        }
    }
    function showmore(id) {
        var d = document.getElementById(id);
        d.style.display = "block";
    }

    function nonemore(id) {
        var d = document.getElementById(id);
        d.style.display = "NONE";
    }
    function yh(id) {
        var d=document.getElementById(id);
        d.style.display="block";
    }

    var tftm=localStorage.getItem("begin");
    if(tftm==1){

    }
    function dateFormat(fmt, date) {
        let ret;
        const opt = {
            "Y+": date.getFullYear().toString(),        // 年
            "m+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "H+": date.getHours().toString(),           // 时
            "M+": date.getMinutes().toString(),         // 分
            "S+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        };
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            };
        };
        return fmt;
    }
</script>
</html>
